<?php
class CalendarController extends CAdmin{
	public function init(){
		$timestamp = (isset($_GET['t'])) ? $_GET['t'] : time();
		list($month, $day , $year) = explode('/', date('m/d/Y', $timestamp));
		$first_day_of_month = date('w',mktime(0,0,0,$month,1,$year));
		$total_days = date('t', $timestamp);
		include self::admin_tpl('calendar_month');
	}
	
	public function set_calendar(){
		$calendar_model = new Calendar_Model();
		if(isset($_POST['dosubmit'])){
			$evt_name = (isset($_POST['evt_name'])) ? $_POST['evt_name'] : '';
			$evt_pm = (isset($_POST['evt_pm']) && $_POST['evt_pm'] == 'yes');
    		$evt_hour = (isset($_POST['evt_hour'])) ? (int)$_POST['evt_hour'] : 0;
			if ($evt_pm){
		        $evt_hour += 12;
		    }
		    if ($evt_hour == 24) {
		       $evt_hour = 12;
		    }
		    else if ($evt_hour == 12){
		       $evt_hour = 0;
		    }
		    $evt_min = (isset($_POST['evt_min'])) ? (int)$_POST['evt_min'] : 0;
    		$evt_notify = (isset($_POST['evt_notify']) &&$_POST['evt_notify'] == 'yes');
    		$data = array();
    		$data['EVENT_NAME'] = $evt_name;
    		$data['EVENT_TSTAMP'] = '2012-05-03'.' '.$evt_hour.':'.$evt_min.':00';
    		$data['NOTIFY'] = $evt_notify;
    		$calendar_model->insert($data);
			if($calendar_model->insert_id()){
				self::showmessage('操作成功！','?m=calendar&c=calendar');
			}
		} else{
			include self::admin_tpl('calendar_detail');
		}
	}
}